package com.ymatou.iapi.godmch.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.condition;
import com.ymatou.iapi.godmch.parameter.setAgentConditionLevelBean;
import com.ymatou.iapi.godmch.service.setAgentConditionLevelCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.markup_level_agent_price;
import com.ymttest.database.model.godmch.markup_level_agent_priceExample;
import com.ymttest.database.sqlwapper.godmch.markup_level_agent_priceWapper;
/**
*设置代理价按条件加价优先级
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_setAgentConditionLevel{
	private static setAgentConditionLevelBean bean;
	private static setAgentConditionLevelCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置代理价按条件加价优先级");
	}

	@Before
	public void caseUp() {
		bean=new setAgentConditionLevelBean();
		call=new setAgentConditionLevelCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setAgentConditionLevel_001() {
		Logger.start(true,"设置代理价按条件加价优先级-一条类型-返回成功");
		try {
			
			Integer mchId=GodmchManageCallService.CreateSellerMch();
		    List<condition> lst=new ArrayList<condition>();
   		    condition con=new condition();
   		    con.setConditionType(5);
   		    con.setConditionLevel(2);
   		    lst.add(con);
	   		bean.setList(lst);
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();			
			
		  markup_level_agent_priceWapper markupConfig=new markup_level_agent_priceWapper();
		  markup_level_agent_priceExample example=new markup_level_agent_priceExample();
		  example.createCriteria().andMch_idEqualTo(mchId);
		  markup_level_agent_price level=markupConfig.selectByExample(example).get(0);
		 	
		  Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		  Logger.verifyEquals(bean.getMchId(), level.getMch_id(), "验证数据库markup_level_agent_price表中的MchId字段与传入的一致");
		  Logger.verifyEquals(bean.getList().get(0).getConditionType(), level.getType_id(), "验证数据库markup_level_agent_price表中的Type_id字段与传入的一致");
		  Logger.verifyEquals(bean.getList().get(0).getConditionLevel(), level.getType_level(), "验证数据库markup_level_agent_price表中的Type_level字段与传入的一致");
			  
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setAgentConditionLevel_002() {
		Logger.start(true,"设置代理价按条件加价优先级-设置两条类型-返回成功");
		try {
			Integer mchId=GodmchManageCallService.CreateSellerMch();
		    List<condition> lst=new ArrayList<condition>();
		    //添加一条
   		    condition con=new condition();
   		    con.setConditionType(5);
   		    con.setConditionLevel(2);
   		    lst.add(con);
   		    //添加两条
   		    con=new condition();
   		    con.setConditionType(3);
   		    con.setConditionLevel(1);
   		    lst.add(con);
	   		bean.setList(lst);
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();			
			
		  markup_level_agent_priceWapper markupConfig=new markup_level_agent_priceWapper();
		  markup_level_agent_priceExample example=new markup_level_agent_priceExample();
		  example.createCriteria().andMch_idEqualTo(mchId);
		  List<markup_level_agent_price> levels=markupConfig.selectByExample(example);
		 	
		  Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		  Logger.verifyEquals(bean.getMchId(), levels.get(0).getMch_id(), "验证数据库markup_level_agent_price表中的MchId字段与传入的一致");
		  Logger.verifyEquals(bean.getList().get(1).getConditionType(), levels.get(0).getType_id(), "验证数据库markup_condition_level表中的Type_id字段与传入的一致");			
		  Logger.verifyEquals(bean.getList().get(0).getConditionType(), levels.get(1).getType_id(), "验证数据库markup_condition_level表中的Type_id字段与传入的一致");
		  Logger.verifyEquals(bean.getList().get(1).getConditionLevel(), levels.get(0).getType_level(), "验证数据库markup_level_agent_price表中的Type_level字段与传入的一致");		
		  Logger.verifyEquals(bean.getList().get(0).getConditionLevel(), levels.get(1).getType_level(), "验证数据库markup_level_agent_price表中的Type_level字段与传入的一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setAgentConditionLevel_003() {
		Logger.start(true,"设置代理价按条件加价优先级-1分钟内不可以再执行-返回成功");
		try {
			Integer mchId=GodmchManageCallService.CreateSellerMch();
		    List<condition> lst=new ArrayList<condition>();
   		    condition con=new condition();
   		    con.setConditionType(5);
   		    con.setConditionLevel(2);
   		    lst.add(con);
	   		bean.setList(lst);
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();		
			call.callService();		
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setAgentConditionLevel_004() {
		Logger.start(true,"设置代理价按条件加价优先级-商户id为空-返回失败");
		try {

		    List<condition> lst=new ArrayList<condition>();
   		    condition con=new condition();
   		    con.setConditionType(5);
   		    con.setConditionLevel(2);
   		    lst.add(con);
	   		bean.setList(lst);
			//bean.setMchId(mchId);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setAgentConditionLevel_005() {
		Logger.start(true,"设置代理价按条件加价优先级-list为空-返回失败");
		try {
			Integer mchId=GodmchManageCallService.CreateSellerMch();
		    List<condition> lst=new ArrayList<condition>();
//   		    condition con=new condition();
//   		    con.setConditionType(5);
//   		    con.setConditionLevel(2);
//   		    lst.add(con);
	   		bean.setList(lst);
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}